/////////////////////////////////////////////////////////////////////////////
//
// XepdtMsgHandler.h
//
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

#include <map>

#include <messagesessionhandler.h>
#include <messageeventhandler.h>
#include <messagefilter.h>

#include <messageeventhandler.h>
#include <messageeventfilter.h>

#include <messagehandler.h>
#include <stanza.h>

#include <chatstatefilter.h>
#include <chatstatehandler.h>

using namespace gloox;

class CXepdtClient;

/////////////////////////////////////////////////////////////////////////////
// CXepdtMessageHandler

class CXepdtMessageHandler : public gloox::MessageHandler
{
// Construction
public:
	CXepdtMessageHandler() {}
	CXepdtMessageHandler( CXepdtClient* pClient ) {
		m_pClient = pClient;
	}
	virtual ~CXepdtMessageHandler() {}

// Override
public:
	virtual void handleMessage( const Message& msg, MessageSession* session = 0 );

private:
	CXepdtClient* m_pClient;

public:
	const static std::string typeChat;
	const static std::string typeVideo;

	const static std::string typeRecvRequest;
	const static std::string typeRecvAccept;
	const static std::string typeRecvRejct;
	const static std::string typeRecvUnknow;

	const static std::string typeSendRequest;
	const static std::string typeSendAccept;
	const static std::string typeSendReject;
	const static std::string typeSendUnknow;

	const static std::string typeNetAddress;

	// Implementation of the video chatting session...
private:
	void OnChatSession ( std::string chatContent,  std::string jid );
};

/////////////////////////////////////////////////////////////////////////////
// CXepdtEventHandler

class CXepdtEventHandler : public gloox::MessageEventHandler
{
// Construction
public:
	CXepdtEventHandler() {}
	CXepdtEventHandler( CXepdtClient* pClient ) {
		m_pClient = pClient;
	}
	virtual ~CXepdtEventHandler() {}

// Override
public:
	virtual void handleMessageEvent( const gloox::JID& from, gloox::MessageEventType event );

private:
	CXepdtClient* m_pClient;
};

class CXepdtChatStateHandler : public gloox::ChatStateHandler
{
// Construction
public:
	CXepdtChatStateHandler() {}
	CXepdtChatStateHandler( CXepdtClient* pClient ) {
		m_pClient = pClient;
	}

	virtual ~CXepdtChatStateHandler() {}

// Override
public:
	virtual void handleChatState( const gloox::JID& from, gloox::ChatStateType state );

private:
	CXepdtClient* m_pClient;
};

/////////////////////////////////////////////////////////////////////////////
// CXepdtSessionHandler

class CXepdtSessionHandler : public gloox::MessageSessionHandler
{
// Construction
public:
	CXepdtSessionHandler();
	CXepdtSessionHandler( CXepdtClient* pClient );

	virtual ~CXepdtSessionHandler();

// Overrides	
public:
	virtual void handleMessageSession( gloox::MessageSession *session );

	void SendChatMessage( std::string& jid, std::string& msg );

	gloox::MessageSession* GetMessageSession( std::string& jid, std::string& res );
	
// Operation
public:
	void Cleanup();

private:
	CXepdtClient* m_pClient;

	typedef struct tagMSG_SESSION {
		gloox::MessageSession*     pMessageSession;
		gloox::MessageEventFilter* pMessageEventFilter;
		gloox::ChatStateFilter*    pChatStateFilter;
		
		CXepdtEventHandler*     pXepdtEventHandler;
		CXepdtChatStateHandler* pXepdtChatStateHandler;
		CXepdtMessageHandler*   pXepdtMessageHandler;
	} MSG_SESSION, * LPMSG_SESSION;

	typedef std::map< std::string, MSG_SESSION > MAP_SESSION;
	typedef std::map< std::string, MSG_SESSION >::iterator IT_MAP_SESSION;

	MAP_SESSION m_mapSession;
};